﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualBasic;

namespace ece750project
{
    public partial class Staff : Form
    {
        public struct paratype
        {
            public int Patient_id;
        }
        public Staff()
        {
            InitializeComponent();
        }

        public paratype para;
        private void button4_Click(object sender, EventArgs e)
        {
            Appointments  f = new Appointments();
            abc_app.Appointments_para.Patient_id = -1;
            abc_app.Appointments_para.Staff_id = abc_app.current_user_personal_info.person_id;
            abc_app.Appointments_para.Direct_appointment_mode = false;
            f.ShowDialog();
            
        }

        private void new_patient_Click(object sender, EventArgs e)
        {
            AddNewPatients ADNP = new AddNewPatients();
            ADNP.ShowDialog();
        }

        private void Staff_FormClosed(object sender, FormClosedEventArgs e)
        {
            
        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void Staff_Load(object sender, EventArgs e)
        {
            staff_name.Text =abc_app.current_user_personal_info.last_name + ", "+abc_app.current_user_personal_info.first_name;
            lbl_supervisor.Text = DB_BusinessRules.get_supervisor_Name(abc_app.current_user_personal_info.person_id);
            btn_visits.Enabled = abc_app.current_user_personal_info.permission_granted;

        }

        private void patient_list_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void patinet_search_Click(object sender, EventArgs e)
        {
            listPatients.Items.Clear();
            DataTable DT=DB_BusinessRules.serch_patient(txt_lastName.Text, txtPhonenumber.Text);
            if (DT == null || DT.Rows.Count==0) { Interaction.Beep(); return; }
            for (int i = 0; i <= DT.Rows.Count - 1; i++)
            {
                int P_ID =Convert.ToInt32(DT.Rows[i]["person_id"]);
                string P_Name = DT.Rows[i]["last_name"].ToString();
                P_Name += ", " + DT.Rows[i]["first_name"].ToString();
                ListViewItem IT=listPatients.Items.Add(P_Name);
                IT.Tag = P_ID;
            } 

        }

        private void listPatients_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (listPatients.SelectedItems[0] == null) return;

            int P_ID = (int)listPatients.SelectedItems[0].Tag;
            abc_app.ADDNewPatient_para.Show_mode = true;
            abc_app.ADDNewPatient_para.P_ID = P_ID;

            AddNewPatients frm = new AddNewPatients();
            frm.ShowDialog();

        }

        private void listPatients_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void listPatients_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (listPatients.SelectedItems[0] == null) return;
                Menu_appointments.Show(listPatients, e.Location);
            }

        }

        private void makeAnAppointmentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listPatients.SelectedItems[0] == null) return;
            int P_ID = (int)listPatients.SelectedItems[0].Tag;
            Appointments f = new Appointments();
            abc_app.Appointments_para.Patient_id = P_ID;
            abc_app.Appointments_para.Staff_id = abc_app.current_user_personal_info.person_id;
            abc_app.Appointments_para.Direct_appointment_mode = true;
            f.ShowDialog();


        }

        private void btn_visits_Click(object sender, EventArgs e)
        {
            DoctorMain f = new DoctorMain();
            f.View_Mode = true;
            f.para.Doc_id = DB_BusinessRules.get_supervisor_ID(abc_app.current_user_personal_info.person_id);
            f.para.Staff_id = abc_app.current_user_personal_info.person_id;
            this.Hide();
            f.ShowDialog();
            this.Show();
        }

        private void getNewAppointmentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listPatients.SelectedItems[0] == null) return;
            int P_ID = (int)listPatients.SelectedItems[0].Tag;
            Appointments f = new Appointments();
            abc_app.Appointments_para.Patient_id = P_ID;
            abc_app.Appointments_para.Staff_id = abc_app.current_user_personal_info.person_id;
            abc_app.Appointments_para.Direct_appointment_mode = false;
            f.ShowDialog();

        }
    }
}
